<?php

namespace App\Models;

use App\Common\Constant\Params;
use App\Services\IStorageService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Merchant extends BaseModel
{
    use Notifiable;

    protected $table = 'merchant';

    protected $primaryKey = 'me_id';

    const CREATED_AT = 'me_add_time';
    const UPDATED_AT = 'me_update_time';

    protected $dateFormat = 'U';

    protected $fillable = [
        'me_id',
        'me_username',
        'me_pass',
        'me_paypass',
        'me_phone',
        'me_money',
        'me_weixin',
        'me_qq',
        'me_bank_name',
        'me_bank_num',
        'me_truename',
        'me_idcard',
        'me_idcard_img1',
        'me_idcard_img2',
        'me_idcard_stutas',
        'me_sex',
        'me_email',
        'me_email_stutas',
        'me_headimg',
        'me_local_area',
        'me_local_address',
        'me_delivery_area',
        'me_delivery_address',
        'me_jd_name',
        'me_jd_url',
        'me_tb_name',
        'me_tb_url',
        'me_status',
        'me_update_time',
        'me_add_time',
        'me_add_ip',
        'me_category',
        'me_phoneps',
        'me_tbww',
        'me_mi_code',
        'me_goods_status',
        'me_points',
    ];

    /**
     * 获取商家是否被封号
     * disabled
     */
    public function getDisabledAttribute()
    {
        return $this->me_status == Params::MERCHANT_STATUS_DISABLE;
    }

    /**
     * 商家用户类型文字
     * category_type
     */
    public function getCategoryTypeAttribute()
    {
        return Params::$MERCHANT_TYPE[$this->me_category];
    }

    /**
     * 获取头像图片url绝对地址
     * headimg_url
     */
    public function getHeadimgUrlAttribute()
    {
        if (empty($this->me_headimg) || $this->me_headimg == 'assets/merchant/member/images/headimg.jpg'){
            return asset('images/headimg.jpg');
        }if (strpos($this->me_headimg,'upload') === 0){
            return 'http://www.lebangdaojia.com/'.$this->me_headimg;
        } else{
            return resolve(IStorageService::class)->getUrl($this->me_headimg);
        }
    }

}
